from core.tools.custom_requests import CustomRequests
from core.tools.get_datetime import GetDateTime
from .base import BaseClient


class Client(BaseClient):
    def __init__(self):
        self.base_url = "http://test.api.my-dt.com"
        # self.appId = "202007091558240001"
        # self.appSecret = "6f1a3dd7279d558ed210ac15c4002ec5"
        # self.privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAK+X1ZUfK/OCqKb9mylMKxwkFRsY+ErvI3/qvXpPjBiMwgwmCVOGyj7dNSkvuMgkdF0AIxX/xVmfKhFRQRaxP2PpsZCdzHshpGm+r8dP+BcWKv+5sspxqcB92S7WBEE+Dg+wFVi++SGFQ9i3zD4tcdte44OnqIOEo2bMGxJ7XCnZAgMBAAECgYAyotNpvGJ9R3mBJnMfNqLb65/Wf53iZhHTqorXgacB0V2ICVP5LU6XUE0rQmLD/Jc91nNHvclYbejAs7DUbWq81epoSG3uN/UwtXNYvYs/a93sfS2bOlo9b5PEebrbbggaloRV01ZsWOjFBP8aU2NDPESFXAPOEC8VnblbO/ZYXQJBAP6aNwbizEmalDRvFqnj5rUb6sWiw3zXLlxKMoPJJZZJrlA2C/+yYIoOp+TnOSpPsOI7KlCoVNcsMYj67gSVFccCQQCwjpcI83s1kNyycSdnwVuIvjyBYi0g7zyC4a5tQAJoXbWNdF2P0oy0NpY+WdVPrBRp8NZHLVe1KFkGgkuJ+kNfAkEAl8kaqylE/1B/sK7VxR0QasKk+YRqpR+oDO9TJEwj83Aj0sAV8S/H7CaGo6nR4860tnrtZD6mrc00DuUCR4sV+wJASpCN3OvnlyHM81eyirEwlTmyl/n8kTI4XhYt8lncKnOZH1qLwRfs8Jc1MLQD0JgeLvfVp03RAuM9ZfBVMrqNBQJAMEJeN+xr7+MnOk4q5irm/TJkeFcieYz8ZsKgg4CYIlGo0Ot93D+8TcST4sNVUEAb/BTEeNcnIaTkzgn0SpfCDQ=="
        self.version = "V1"
        self.appId = "2018030900000001"
        self.appSecret = "c9a88f4206416de82c839a077c71f67f"
        self.priv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QIDAQAB"
        self.businessDataEncryptType = ""

    def query_list(self, latitude="31.23680019676275", longitude="121.6665488405102", currentRecord=1, recordCount=10):
        """
        :param latitude: 纬度
        :param longitude: 经度
        :param currentRecord: 用于分页
        :param adcode: 城市行政编码
        :param recordCount: 每页x条
        :return:
        """
        url = "/gas/shop/getShopList"
        data = {
            "latitude": latitude,
            "longitude": longitude,
            "currentRecord": currentRecord,
            "recordCount": recordCount,
            "adcode": "330100"
        }
        ciphertext = self.des_encrypt(data)

        response = self.post(url, json=data)
        return response

    def detail(self, shopId, latitude, longitude):
        """
        :param shopId:
        :param latitude:
        :param longitude:
        :return:
        """
        url = "/gas/shop/getShop"
        data = {
            "shopId": shopId,
            "latitude": latitude,
            "longitude": longitude,
        }
        response = self.post(url, json=data)

    def create_order(self, paymentAmount, totalAmount, couponId, gasGunId, longitude, latitude, shopId):
        """
        :param paymentAmount:
        :param totalAmount:
        :param couponId:
        :param gasGunId:
        :param longitude:
        :param latitude:
        :param shopId:
        :return:
        """
        data = {
            "shopId": shopId,
            "latitude": latitude,
            "longitude": longitude,
            "paymentAmount": paymentAmount,
            "totalAmount": totalAmount,
            "couponId": couponId,
            "gasGunId": gasGunId,
        }
        url = "/gas/shop/createGasOrder"
        response = self.post(url, json=data)

    def query_order(self, orderId, isBackLoopQuery=1):
        """
        :param orderId: 订单id
        :param isBackLoopQuery: 是否增强查询 1是 0否 建议传1
        :return:
        """
        data = {
            "orderId": orderId,
            "longitude": isBackLoopQuery,
        }
        url = "/gas/order/selectOrderInfo"
        response = self.post(url, json=data)

    def user_login(self, mobile, outUserId):
        """
        :param mobile: 手机号
        :param outUserId: 第三方用id
        :return:
        """
        data = {
            "outUserId": outUserId,
            "mobile": mobile,
        }
        url = "/gas/user/thirdUserRegister"
        response = self.post(url, json=data)


dt_client = Client()
